Skip to content

refactor: rework extension API for iron-remote-desktop#762

Merged
Benoît Cortier (CBenoit) merged 1 commit into
masterfrom
refactor/iron-remote-web-extension
Apr 21, 2025
Merged

refactor: rework extension API for iron-remote-desktop#762
Benoît Cortier (CBenoit) merged 1 commit into
masterfrom
refactor/iron-remote-web-extension

Conversation

@CBenoit
Copy link
Copy Markdown
Member

@CBenoit Benoît Cortier (CBenoit) commented Apr 21, 2025

Rework the extension API for iron-remote-desktop as per #749 (review)

I used this PR as basis: #761

Comment on lines +207 to 212
iron_remote_desktop::extension_match! {
match ext;
|pcb: String| { self.0.borrow_mut().pcb = Some(pcb) };
|kdc_proxy_url: String| { self.0.borrow_mut().kdc_proxy_url = Some(kdc_proxy_url) };
|display_control: bool| { self.0.borrow_mut().use_display_control = display_control };
}
Copy link
Copy Markdown
Member Author

@CBenoit Benoît Cortier (CBenoit) Apr 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We directly use JsValue API without any smart trick.
No extra dependency required for that.
For now there is no extension requiring to pass an "object", but if we had one, we could use the Reflect module of js_sys, that we already depend on, to get the individual fields.

@github-actions
Copy link
Copy Markdown

Coverage Report 🤖 ⚙️

Past:
Total lines: 30471
Covered lines: 19506 (64.01%)

New:
Total lines: 30483
Covered lines: 19506 (63.99%)

Diff: -0.03%

[this comment will be updated automatically]

Comment on lines +4 to +40
#[macro_export]
macro_rules! extension_match {
( @ $jsval:expr, $value:ident, String, $operation:block ) => {{
if let Some($value) = $jsval.as_string() {
$operation
} else {
warn!("Unexpected value for extension {}", stringify!($ident));
}
}};
( @ $jsval:expr, $value:ident, f64, $operation:block ) => {{
if let Some($value) = $jsval.as_f64() {
$operation
} else {
warn!("Unexpected value for extension {}", stringify!($ident));
}
}};
( @ $jsval:expr, $value:ident, bool, $operation:block ) => {{
if let Some($value) = $jsval.as_bool() {
$operation
} else {
warn!("Unexpected value for extension {}", stringify!($ident));
}
}};
( @ $jsval:expr, $value:ident, JsValue, $operation:block ) => {{
let $value = $jsval;
$operation
}};

( match $ext:ident ; $( | $value:ident : $ty:ident | $operation:block ; )* ) => {
let ident = $ext.ident();

match ident {
$( stringify!($value) => $crate::extension_match!( @ $ext.into_value(), $value, $ty, $operation ), )*
unknown_extension => ::tracing::warn!("Unknown extension: {unknown_extension}"),
}
};
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helper macro to extract extension values. This is not strictly needed, but it’s less boilerplate in the consumer code.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@CBenoit Benoît Cortier (CBenoit) merged commit f287e16 into master Apr 21, 2025
10 checks passed
@CBenoit Benoît Cortier (CBenoit) deleted the refactor/iron-remote-web-extension branch April 21, 2025 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants